//
//   YRTCustomSearchBar.h
//  JiaJiaLi_APP
//
//  Created by Mr.Gao on 2019/5/20.
//  Copyright © 2019年 GaoGuang. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN


typedef NS_ENUM(NSUInteger, GGCustomSearchBarIconAlign)
{
    GGCustomSearchBarIconAlignLeft,
    GGCustomSearchBarIconAlignCenter
};

@class GGCustomSearchBar;

@protocol GGCustomSearchBarDelegate <UIBarPositioningDelegate>

@optional

/** 是否应该开始编辑 */
- (BOOL)searchBarShouldBeginEditing:(GGCustomSearchBar *)searchBar;

- (void)searchBarTextDidBeginEditing:(GGCustomSearchBar *)searchBar;

- (BOOL)searchBarShouldEndEditing:(GGCustomSearchBar *)searchBar;

- (void)searchBarTextDidEndEditing:(GGCustomSearchBar *)searchBar;

/** 文本发生改变 */
- (void)searchBar:(GGCustomSearchBar *)searchBar textDidChange:(NSString *)searchText;

- (BOOL)searchBar:(GGCustomSearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
/** 搜索按钮点击 */
- (void)searchBarSearchButtonClicked:(GGCustomSearchBar *)searchBar;
/** 取消按钮点击 */
- (void)searchBarCancelButtonClicked:(GGCustomSearchBar *)searchBar;

@end

@interface GGCustomSearchBar : UIView
/**
 * 搜索框的代理
 */
@property (nullable, nonatomic, weak) id<GGCustomSearchBarDelegate> delegate;

/**
 * 搜索框文本
 */
@property (nullable, nonatomic, copy) NSString *text;

/**
 * 搜索框文本颜色
 */
@property (nullable, nonatomic, strong) UIColor *textColor;

/** 搜索框边框颜色 */
@property (nullable, nonatomic, strong) UIColor *fieldBorderColor;

/**
 * 搜索框文本字体
 */
@property (nullable, nonatomic,strong) UIFont *textFont;

/**
 * 搜索框提示信息
 */
@property (nullable, nonatomic, copy) NSString *placeholder;

/**
 * 搜索框提示信息颜色
 */
@property (nullable, nonatomic, strong) UIColor *placeholderColor;

/**
 * 搜索框颜色
 */
@property (nullable, nonatomic, strong) UIColor *textFieldColor;

/**
 * 光标色
 */
@property (nullable, nonatomic, strong) UIColor *cursorColor;

/**
 * 左边icon的图片
 */
@property (nonatomic, strong) UIImage *iconImage;
@property (nonatomic, strong) UIImage *backgroundImage;

/**
 * 右边取消按钮
 */
@property (nullable, nonatomic, strong) UIButton *cancelButton;
/** 是否隐藏取消按钮 */
@property (nonatomic) BOOL isHiddenCancelButton;
/** 取消按钮是否固定在右边 */
@property (nonatomic) BOOL isCancelButtonFixed;

/**
 * 输入框的风格
 */
@property (nonatomic) UITextBorderStyle textBorderStyle;

/**
 * 键盘类型
 */
@property (nonatomic) UIKeyboardType keyboardType;

/**
 * 左边icon的位置
 */
@property (nonatomic) GGCustomSearchBarIconAlign iconAlign;

@property (nonatomic, strong) UIView *inputAccessoryView;

@property (nonatomic, strong) UIView *inputView;

- (BOOL)isFirstResponder;
/** 失去第一响应者 */
- (BOOL)resignFirstResponder;
/** 成为第一响应者 */
- (BOOL)becomeFirstResponder;

- (void)setAutoCapitalizationMode:(UITextAutocapitalizationType)type;

@end

NS_ASSUME_NONNULL_END
